;; ---------- ---------- ---------- ---------- ---------- ---------- ----------
;; Acknowledgements: https://www.emacswiki.org/emacs/IndentingText
;;
;; NOTE: Removed tab and backtab because they break in markdown-mode.
;;
;; NOTE: cua-mode `C-RET` select region and then space/backspace to do the same
;;       as the manual settings 1-space version.
;;
;; ---------- ---------- ---------- ---------- ---------- ---------- ----------

;; ---------- For automated settings ----------
(setq indent-according-to-mode t)
(defun protoculture-web-mode-hook ()
  (setq web-mode-markup-indent-offset 2)
  (setq web-mode-script-indent-offset 2)
  (setq web-mode-css-indent-offset 2)
  (setq web-mode-code-indent-offset 2)
  (setq web-mode-block-padding 0)
  (setq web-mode-script-padding 0)
  (setq web-mode-style-padding 0))
(add-hook 'web-mode-hook 'protoculture-web-mode-hook)
;;(smart-tabs-insinuate 'c)
(add-to-list 'auto-mode-alist '("\\.vue\\'" . web-mode))
;; ---------- END For automated settings ----------

;; ---------- For manual settings ----------
;; Shift the selected region right if distance is postive, left if
;; negative

(defun shift-region (distance)
  (let ((mark (mark)))
    (save-excursion
      (indent-rigidly (region-beginning) (region-end) distance)
      (push-mark mark t t)
      ;; Tell the command loop not to deactivate the mark
      ;; for transient mark mode
      (setq deactivate-mark nil))))

(defun shift-right-long ()
  (interactive)
  (shift-region 4))

(defun shift-left-long ()
  (interactive)
  (shift-region -4))

(defun shift-right ()
  (interactive)
  (shift-region 1))

(defun shift-left ()
  (interactive)
  (shift-region -1))

(global-set-key [s-S-right] 'shift-right-long)
(global-set-key [s-S-left] 'shift-left-long)
(global-set-key [C-S-right] 'shift-right)
(global-set-key [C-S-left] 'shift-left)

;; ---------- END For manual settings ----------

;; ---------- For untabifying ----------
(defun untabify-whole-buffer ()
    "Untabify whole buffer."
    (interactive)
    (untabify (point-min) (point-max)))

(global-set-key (kbd "s-x s-s") 'untabify-whole-buffer)
;; ---------- END For untabifying ----------

(provide 'protoculture-indentation)
